/*
 *      main_win.cpp
 *      
 *      Copyright 2009 AzureSky <AzureSky.fedora@gmail.com>
 *      
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */

#include "main_win.h"

main_win::main_win(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& refGlade):
	Gtk::Window(cobject),
	refXml(refGlade)
{
	init_gui();
}

main_win::~main_win()
{
}

void main_win::init_gui()
{
	const Glib::RefPtr<Gdk::Pixbuf>& pixbuf = Gdk::Pixbuf::create_from_inline(24+1024,icon_win);
	set_default_icon(pixbuf);

	//const Glib::RefPtr<Gdk::Pixbuf>& logo = Gdk::Pixbuf::create_from_inline(24+65536,mylogo);
	//refXml -> get_widget("head_img",my_logo);
	//my_logo -> set(logo);

	refXml -> get_widget_derived("main_notebook",my_notebook);
	my_notebook -> set_show_tabs(false);

	refXml -> get_widget("b_base",base_info);
	base_info -> signal_clicked().connect( sigc::bind<int>( sigc::mem_fun(*this,&main_win::change_page),0 ) );

	refXml -> get_widget("b_kernel",kernel_info);
	kernel_info -> signal_clicked().connect( sigc::bind<int>( sigc::mem_fun(*this,&main_win::change_page),1 ) );

	refXml -> get_widget("b_net",net_info);
	net_info -> signal_clicked().connect( sigc::bind<int>( sigc::mem_fun(*this,&main_win::change_page),2 ) );

	refXml -> get_widget("b_proc",proc_info);
	proc_info -> signal_clicked().connect( sigc::bind<int>( sigc::mem_fun(*this,&main_win::change_page),3 ) );

	refXml -> get_widget("b_gconf",gconf_info);
	gconf_info -> signal_clicked().connect( sigc::bind<int>( sigc::mem_fun(*this,&main_win::change_page),4 ) );

	refXml -> get_widget("b_about",about_info);
	about_info -> signal_clicked().connect( sigc::bind<int>( sigc::mem_fun(*this,&main_win::change_page),5 ) );
	
	refXml -> get_widget("warning_dialog",warning_dialog);
}

void main_win::change_page(int page_num)
{
	int temp;
	if(page_num == 1){
		temp = warning_dialog ->run();
		warning_dialog -> hide();
		if(temp == 1){
			//if((pid = fork()) == 0){
				//execl("linux-helper-sysctl",NULL);
				system("linux-helper-sysctl");
			//}
		}
		else
			my_notebook -> set_current_page(0);
	}else
		my_notebook -> set_current_page(page_num);
}
